<template>
    <sc-dialog v-model="visible" title="提现" :width="500" destroy-on-close @closed="$emit('closed')">
        <el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="right">
            <el-form-item label="部门" prop="label">
                {{ department.title }}
            </el-form-item>
            <el-form-item label="余额" prop="label">
                {{ department.amount }}
            </el-form-item>
            <el-form-item label="提现金额" prop="amount">
                <el-input-number v-model="form.amount" :min="0.01" :max="department.amount" clearable></el-input-number>
                <!-- <div class="el-form-item-msg">每个手机号之间用英文的逗号,隔开</div> -->
            </el-form-item>
            <el-form-item label="备注" prop="remark">
                <el-input type="textarea" :row="3" v-model="form.remark" clearable></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
            <el-button @click="visible = false">取 消</el-button>
            <el-button type="primary" :loading="isSaveing" @click="submit()">发 放</el-button>
        </template>
    </sc-dialog>
</template>

<script>
export default {
    emits: ['success', 'closed'],
    data () {
        return {
            visible: true,
            isSaveing: false,
            department: {},
            form: {
                amount: 0
            },
            //验证规则
            rules: {
                amount: [
                    { required: true, message: '请填写提现的金额', trigger: 'change' }
                ],
            }
        }
    },
    mounted () {

    },
    methods: {
        open () {
            this.visible = true;
            return this;
        },
        setData (data) {
            this.department = data
        },
        submit () {
            this.$refs.dialogForm.validate(async (valid) => {
                if (valid) {
                    this.isSaveing = true;
                    this.$API.app.withdrawal.save.post(this.form)
                        .then((res) => {
                            this.isSaveing = false
                            this.$message.success(res.message)
                            this.visible = false;
                            this.$emit('success')
                        })
                        .catch(() => {
                            this.isSaveing = false
                        })
                }
            })
        }
    }
}
</script>

<style></style>
